<template>
	<view class="container">
		<popup-active :visible.sync="showHonor" :popScreenList="popScreenList"></popup-active>
		<view class="tabs">
			<!-- tab-header -->
			<view class="tab-header">
				<!-- <view class="tab-title"><view :class="{ active: isActive == 1 }" @click="chenked(1)">精彩活动</view></view> -->
				<!-- #ifdef H5 -->
				<!-- <view class="tab-title"><view :class="{ active: isActive == 2 }" @click="chenked(2)">云课堂</view></view> -->
				<!-- #endif -->
				<view class="tab-title"><view :class="{ active: isActive == 3 }" @click="chenked(3)">人物志</view></view>
			</view>
			<!-- nav-item -->
			<view class="tab-content activity" v-if="isActive == 1">
				<view class="box-item active-tab" @click="jumpHandle_tab1(item)" v-for="(item, index) in renwuArr1" :key="index">
					<image class="box-item-image" :src="item.activityPic" mode="aspectFill"></image>
					<view class="box-item-content">
						<view class="title fontB">
							<text>{{ item.activityName }}</text>
						</view>
						<view class="active-detail-info" v-for="(_item, index) in item.timeAddressList" :key="index">
							<view class="date">
								<text>活动时间：{{ _item.activityTime }}</text>
							</view>
							<view class="area">
								<text class="txt">活动地点：{{ _item.activityAddress }}</text>
							</view>
						</view>
						<view class="collect">
							<view class="care" @click.stop="handleClick(item)">
								<image :src="like" mode="aspectFill" v-if="item.isLike == '2'"></image>
								<image :src="islike" mode="aspectFill" v-else></image>
								<text>{{ item.likeNum || 0 }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="tab-content class-room" v-if="isActive == 2 && renwuArr2.length != 0">
				<view class="class-tab" v-for="(item, index) in renwuArr2" :key="index" @click="jumpHandle_tab2(item)">
					<image class="box-item-image" :src="item.imgUrl" mode="aspectFill"></image>
					<view class="box-item-content">
						<view class="title">{{ item.className }}</view>
						<view class="collect">
							<view class="care" @click.stop="startHandle(item, 1, index)" v-if="emptyArr.length != 0 && item.likeType == 2">
								<image src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/images/interaction/start.png" mode="aspectFill"></image>
								<text>{{ item.favoriteNum || 0 }}</text>
							</view>
							<view class="care" @click.stop="startHandle(item, 2, index)" v-else>
								<image src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/images/interaction/startActive.png" mode="aspectFill"></image>
								<text>{{ item.favoriteNum || 0 }}</text>
							</view>
							<view class="view">
								<image src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/home/shoucang.png" mode="aspectFill"></image>
								<text>{{ item.viewNum || 0 }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="tab-content people" style="background:#F7F7F7;" v-if="isActive == 3">
				<view @click="jumpHandle_tab3(item)" class="people-tab" v-for="(item, index) in renwuArr" :key="index">
					<image class="box-item-image" :src="item.imgUrl" mode="aspectFill"></image>
					<view class="tip" v-if="item.orgName">{{ item.orgName | dataFormat }}</view>
					<view class="right">
						<view class="fontB right-title">{{ item.contentName }}</view>
						<view class="right-desc ellipsis2">{{ item.contentIntroduce }}</view>
					</view>
				</view>
			</view>
			<mix-load-more :status="loading"></mix-load-more>
		</view>
		<uni-popup-slient ref="slient" :endTime="endTime" :tip="title"></uni-popup-slient>
	</view>
</template>

<script>
import http from '../../common/request.js';
import uniPopupSlient from '@/components/uni-popup/uni-popup-dialog-silent.vue';
import popupActive from '@/components/popup-activity/popup-activity.vue';
import mixLoadMore from '@/components/mix-load-more/mix-load-more';
import { getCommonShareInfo } from '@/common/utils.js';
export default {
	onShareAppMessage() {
		return getCommonShareInfo();
	},
	components: {
		popupActive,
		uniPopupSlient,
		mixLoadMore
	},
	data() {
		return {
			popScreenList: [],
			showHonor: false,
			emptyArr: [],
			like: '//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/heart_empty.png',
			islike: '//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/heart_fill.png',
			pageNum: 1,
			pageSize: 10,
			associationId: '1',
			associationName: '',
			pages: [],
			pages2: [],
			loading: 0,
			loadingType: 0,
			loading1: 0,
			loading2: 0,
			isActive: 3,
			renwuArr: [],
			renwuArr2: [],
			renwuArr1: [],
			title: '云课堂正在建设中，敬请期待。',
			endTime: '',
			oldData: {}
		};
	},
	onLoad: function(option) {
		//页面第一次加载是会触发，可以把一些不需要实时更新的数据放入
		this.associationId = option.associationId;
		this.associationName = option.associationName;
		uni.setNavigationBarTitle({
			title: option.associationName
		});
		this.getMoreNews();
	},
	onReachBottom: function() {
		//当划到最底部的时候触发事件
		if (this.loading !== 2) {
			if (this.isActive == 3) {
				this.getMoreNews(); //到底之后会触发getMoreNews()函数;
			}
			if (this.isActive == 1) {
				this.getMoreNews1(); //到底之后会触发getMoreNews()函数;
			}
			if (this.isActive == 2) {
				this.getMoreNews2(); //到底之后会触发getMoreNews()函数;
			}
		}
	},
	filters: {
		getTimeAddressList(key, item) {
			if (item && item.timeAddressList && item.timeAddressList[0]) {
				return item.timeAddressList[0][key] || '';
			}
			return '';
		},
		dataFormat(msg) {
			if (msg) {
				return msg.slice(0, 2);
			}
		}
	},
	methods: {
		handleClick(item) {
			let url = '';
			if (item.isLike == '2') {
				url = 'api/activity/dataIncr'; // 点赞
			} else {
				url = 'api/activity/dataDecr'; // 取消点赞
			}
			http(url, {
				method: 'post',
				data: {
					activityId: item.activityId
				}
			}).then(result => {
				const data = result.data || {};
				item.likeNum = data.count || 0;
				item.isLike = data.isLike;
				const list = result.popScreen || [];
				if (list.length > 0) {
					this.showHonor = true;
					this.popScreenList = list;
				}
			});
		},
		updateActive(cont, type) {
			this.oldData.isLike = type;
			this.oldData.likeNum = cont;
		},
		startHandle(item, index, index1) {
			http('/api/subjectClass/favorites', {
				method: 'post',
				data: {
					classId: item.classId,
					likeType: index
				}
			}).then(result => {
				item.likeType = result.data.likeType;
				item.favoriteNum = result.data.count;
			});
		},
		getMoreNews: function() {
			this.loading = 1;
			http('/api/sysContentInfo/biography/biographyList', {
				method: 'post',
				data: {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					contentSubject: 3,
					community: this.associationId
				}
			}).then(result => {
				var pages = result.data.records || [];
				this.renwuArr = this.renwuArr.concat(pages); //进行数据的累加
				if (pages.length == this.pageSize) {
					this.pageNum++; //页数的++
					this.loading = 0;
				} else {
					this.loading = 2;
				}
				this.loading = this.renwuArr.length === 0 ? 3 : this.loading;
			});
		},
		getMoreNews1: function() {
			//数据到底,触发这个函数
			this.loading = 1;
			http('/api/sysAssociationActivity/pageList', {
				method: 'POST',
				data: {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					baseEntity: {
						associationId: this.associationId
					}
				}
			}).then(result => {
				var pages = result.rows || [];
				this.renwuArr1 = this.renwuArr1.concat(pages); //进行数据的累加
				if (pages.length == this.pageSize) {
					this.pageNum++; //页数的++
					this.loading = 0;
				} else {
					this.loading = 2;
				}
				this.loading = this.renwuArr1.length === 0 ? 3 : this.loading;
			});
		},
		getMoreNews2(tag) {
			if (tag) {
				this.pageNum = 1;
			}
			//数据到底,触发这个函数
			this.loading = 1;
			http('/api/subjectClass/subjectInfoClassList?pageNum=' + this.pageNum + '&pageSize=' + this.pageSize + '&socialCommunity=' + this.associationId, {
				method: 'get'
			}).then(result => {
				var pages = result.data;
				this.emptyArr = result.data || [];
				if (tag) {
					this.renwuArr2 = pages;
				} else {
					this.renwuArr2 = this.renwuArr2.concat(pages); //进行数据的累加
				}
				if (result.data.length == this.pageSize) {
					this.pageNum++; //页数的++
					this.loading = 0;
				} else {
					this.loading = 2;
				}
				this.loading = this.renwuArr2.length === 0 ? 3 : this.loading;
			});
		},
		jumpHandle_tab1(data) {
			this.oldData = data;
			const { activityId, activityName } = data;
			//埋点
			this.$umaTrackEvent('activity', { activityId, activityName, associationId: this.associationId, associationName: this.associationName, source: '社群精彩活动' });
			uni.navigateTo({
				url: '/activity/info/index?activityId=' + activityId,
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		jumpHandle_tab2(item) {
			http('/api/subjectClass/watch', {
				method: 'post',
				data: {
					classId: item.classId
				}
			}).then(result => {
				item.viewNum = item.viewNum + 1;
				uni.navigateTo({
					url: '../web_view?url=' + encodeURIComponent(item.classUrl),
					animationType: 'pop-in',
					animationDuration: 200
				});
			});
		},
		jumpHandle_tab3({ contentId, originalFlag, contentUrl }) {
			if (originalFlag === 0) {
				this.toWebView(contentUrl);
			} else {
				uni.navigateTo({
					url: '../../home/community/biographyDetails?contentId=' + contentId,
					animationType: 'pop-in',
					animationDuration: 200
				});
			}
		},
		toWebView(url) {
			// #ifdef H5
			location.href = url;
			// #endif
			// #ifdef MP-WEIXIN
			uni.navigateTo({
				url: '../web_view?url=' + encodeURIComponent(url),
				animationType: 'pop-in',
				animationDuration: 200
			});
			// #endif
		},
		chenked(type) {
			// this.isActive = type;
			// this.renwuArr1 = [];
			// this.renwuArr = [];
			// this.renwuArr2 = [];
			// this.pageNum = 1;
			// if (type == 1) {
			// 	this.getMoreNews1();
			// } else if (type == 2) {
			// 	this.getMoreNews2();
			// } else if (type == 3) {
			// 	this.getMoreNews();
			// }
		}
	}
};
</script>

<style lang="less" scoped>
image {
	vertical-align: middle;
}
.tip {
	width: 64rpx;
	height: 30rpx;
	line-height: 30rpx;
	display: flex;
	// align-items: center;
	justify-content: center;
	color: #fff;
	background: #f39800;
	font-size: 20rpx;
	position: absolute;
	left: 0;
	top: 16rpx;
	padding-left: 0rpx !important;
}
.container {
	background-color: #f7f7f7;
	.tabs {
		color: #66645d;
		font-size: 26rpx;

		.tab-header {
			border-top: 1rpx solid #f2f2f2;
			background-color: #fff;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: 10;
			display: flex;

			.tab-title {
				height: 88rpx;
				line-height: 88rpx;
				width: 100%;
				text-align: center;
				font-size: 26rpx;
				color: #8a8c8d;

				.active {
					position: relative;
					color: #66645d;
				}

				.active::after {
					content: '';
					position: absolute;
					width: 40rpx;
					height: 6rpx;
					border-radius: 12rpx;
					background-color: #66645d;
					left: 0;
					right: 0;
					bottom: 11rpx;
					margin: auto;
				}
			}
		}

		.tab-content {
			margin-top: 112rpx;
			padding-left: 40rpx;
			padding-right: 40rpx;
			.active-tab,
			.class-tab,
			.people-tab {
				margin-bottom: 23rpx;
				border-radius: 12rpx;
				overflow: hidden;
				.box-item-image {
					height: 250rpx;
					width: 100%;
				}

				.box-item-content {
					background: #fff;
					padding: 20rpx 24rpx;
					.title {
						font-size: 30rpx;
						font-weight: 500;
						color: #66645d;
						line-height: 42rpx;
						margin-bottom: 12rpx;
						line-height: 42rpx;
						// font-family: 'PingFangSC-Regular';
						// font-family: "PingFang SC Medium, PingFang SC";
					}
					.active-detail-info {
						margin-bottom: 8rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #8a8c8d;
						.date,
						.area {
							line-height: 40rpx;
						}
						.date {
							margin-bottom: 8rpx;
						}
						&:last-child {
							margin-bottom: 0;
						}
					}

					.collect {
						font-size: 24rpx;
						font-weight: 400;
						color: #b2b1ae;
						text-align: right;
						.care {
							display: inline-flex;
							align-items: center;
							padding: 10rpx 0 10rpx 10rpx;
							image {
								width: 30rpx;
								height: 30rpx;
								margin-right: 12rpx;
							}
						}
					}
				}
			}
			&.class-room {
				display: flex;
				flex-wrap: wrap;
				.class-tab {
					width: calc(50% - 12rpx);
					&:nth-child(2n) {
						margin-left: 12rpx;
					}
					&:nth-child(2n + 1) {
						margin-right: 12rpx;
					}
					.box-item-image {
						height: 140rpx;
						width: 100%;
					}
					.box-item-content {
						.title {
							font-size: 28rpx;
							font-weight: 300;
							color: #66645d;
							height: 80rpx;
							line-height: 40rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							margin-bottom: 24rpx;
						}

						.collect {
							display: flex;
							justify-content: space-between;

							.care,
							.view {
								padding: 10rpx 10rpx 10rpx 0;
								display: flex;
								align-items: center;
								image {
									width: 30rpx;
									height: 30rpx;
									margin-right: 12rpx;
								}
								text {
									line-height: 1;
								}
							}
							.view {
								padding: 10rpx 0 10rpx 10rpx;
							}
						}
					}
				}
			}
		}

		.people-tab {
			display: flex;
			padding-bottom: 23rpx;
			margin-bottom: 23rpx;
			overflow: initial !important;
			position: relative;
			&::after {
				content: '';
				position: absolute;
				left: -12rpx;
				right: -12rpx;
				bottom: 0;
				background-color: #e7e7e6;
				height: 2rpx;
				transform: scaleY(0.5);
			}

			&:last-child {
				&::after {
					height: 0;
				}
			}

			.box-item-image {
				width: 275rpx !important;
				height: 160rpx !important;
				margin-right: 20rpx;
				flex-shrink: 0;
				border-radius: 12rpx;
			}

			.right {
				.right-title {
					font-size: 30rpx;
					font-weight: 500;
					color: #66645d;
					line-height: 42rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
				}

				.right-desc {
					font-size: 26rpx;
					color: #8a8c8d;
					margin-top: 26rpx;
					line-height: 37rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					word-break: break-all;
				}
			}
		}
	}
}
</style>
